var http = require('http');
var url = require('url');
var fs = require('fs');
/** node http 如何处理post请求*/
var querystring =require('querystring');

http.createServer(function (req,res) {

    var data='';
    var urlObj = url.parse(req.url,true);
    res.writeHead(200,{'Content-Type':'text/html;charset=utf8'});

    if (urlObj.pathname=='/'){
        fs.readFile('template/login.html',function (err,data) {
            res.end(data.toString());
        })
    }


    if(urlObj.pathname=='/login'){

        req.on('data',function (chunk) {
                  data+=chunk;
              })

        req.on('end',function () {

            data = querystring.parse(data);

            console.log(data.username);
            res.end(data.username);



        })

    }

}).listen(3000);


console.log("the server is running on port 3000");